from models.meta import BaseDocument, IdField, fields, BaseEmbeddedDocument


class EmailSettings(BaseEmbeddedDocument):
    server_host = fields.StringField(max_length=32)
    server_port = fields.IntField(default=25)
    email = fields.EmailField()
    password = fields.StringField(max_length=32)
    encrypt = fields.IntField(choices=[0, 1, 2], default=0)  # 0 none 1 SSL 2 STARTTLS
    email_prefix = fields.StringField(max_length=32, default='')


class WebGlobalConfig(BaseDocument):
    meta = {'collection': "scan_global_config", 'primary_key': 'config_id'}

    access_token_limit = fields.IntField(min_value=0, default=120)  # unit: min
    refresh_token_limit = fields.IntField(min_value=0, default=10)
    config_id = IdField(unique=True, required=True)
    note = fields.StringField(max_length=32, default='')
    net_map_disabled = fields.BooleanField(default=True)
    net_map_host = fields.StringField(max_length=256, default='')
    email_settings = fields.EmbeddedDocumentField(
        default=EmailSettings, document_type=EmailSettings
    )
    max_retry_count = fields.IntField(min_value=0, default=5)
    locked_time = fields.IntField(min_value=0, default=20)
    max_multiple_devices = fields.IntField(min_value=1, default=3)
    task_session_count = fields.IntField(default=0)
    login_log = fields.BooleanField(default=True)
    operate_log = fields.BooleanField(default=True)
